package com.hyy.service.serviceImpl;

import com.hyy.bean.MaskOrder;
import com.hyy.bean.Merchandise;
import com.hyy.bean.OrderProduct;
import com.hyy.dao.OrderDao;
import com.hyy.dao.OrderProductDao;
import com.hyy.dao.daoImpl.OrderDaoImpl;
import com.hyy.dao.daoImpl.OrderProductDaoImpl;
import com.hyy.service.OrderService;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

public class OrderServiceImpl implements OrderService {
	OrderDao orderDao = new OrderDaoImpl();
	OrderProductDao orderProductDao = new OrderProductDaoImpl();

	@Override
	public boolean insertOrder(MaskOrder order,String oid,Map<Merchandise,Long> cartMerchandises) {
		boolean flag1 =false;
		boolean flag2 = false;
		try {
			flag1 = orderDao.insertOrder(order);
			for (Map.Entry<Merchandise,Long> entry : cartMerchandises.entrySet()) {
				flag2 = orderProductDao.insert(oid, entry.getKey(),entry.getValue());
			}
			return flag1&&flag2;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public List<MaskOrder> showOrderByUid(Long uid) {
		try {
			return orderDao.showAllByUid(uid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public List<OrderProduct> showProductByOid(String oid) {
		try {
			return orderProductDao.showProductByOid(oid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
